home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / util / bsindex1 / part01 / src / bbsindex.h < prev    next >
C/C++ Source or Header  |  1990-02-02  |  12KB  |  347 lines

  1. /*
  2.  *        BBSINDEX.H
  3.  *    
  4.  *        All the standard variables and other stuff used by all the modules
  5.  *        of BBSindex, and standard BBS-PC! headers (with a few modifications).
  6.  *
  7.  *        Important note: This header file cannot be precompiled with
  8.  *        Lattice C V5.02, because of a bug which prevents bit fields
  9.  *        from working properly when they are precompiled.
  10.  */
  11.  
  12. #include "bbs.h"
  13.  
  14. #define TRUE    1
  15. #define FALSE    0
  16.  
  17. #define BTOK(x) (((x)+1023)>>10)    /* Convert file size into K */
  18.  
  19. /*
  20.  *        Default values for command line parameters and script commands
  21.  */
  22.  
  23. #define FORMAT        "%15n %w %-6x-%b{B,T}  %c\n"
  24. #define UDNAME        "UDHEAD.DAT"
  25. #define CFGNAME        "CFGINFO.DAT"
  26. #define PROGSCRIPT    "BBSCRIPT"
  27. #define DEFSCRIPT    "BBSindex.scr"
  28.  
  29. /*
  30.  *    Blocksize determines the largest contiguous memory segment which is
  31.  *    needed. Larger values give faster processing, but need more continuous
  32.  *    memory.
  33.  */
  34.  
  35. #define    BLOCKSIZE    160                /* Number of records/block (~16K)        */
  36. #define MAXOUT        1024            /* The maximum length of an output line    */
  37. #define    MAXCOM        1024            /* Maximum size of a single command        */
  38. #define MAXSUB        256                /* Maximum size of a sub format string    */
  39. #define FRAGBLOCK    8192            /* Memory block to allocate in mymalloc */
  40. #define FRAGTHRESH    200                /* Threshold for mem reqs in mymalloc    */
  41. #define BUFSIZE        8192            /* Maximum size of output buffer        */
  42. #define MAXEXPR        100                /* Max number of items in an expression    */
  43. #define MAXDIRENT    1000            /* Maximum number of unknown dir files    */
  44. #define DIRFRAG        100                /* Number of dir entries/block alloced    */
  45. #define DIRNAMESIZE    80                /* Maximum length of directory name        */
  46. #define MACROLEN    20                /* Maximum length of macro name            */
  47. #define MAXMACRO    50                /* Maximum number of macros allowed        */
  48. #define MAXNEST        10                /* Max number of macro nesting levels    */
  49. #define MAXCONST    20                /* Maximum length of a constant name    */
  50.  
  51. /* Note: MAXSUB above is allocated on the stack, so don't make it too big */
  52.  
  53. /*
  54.  *        This structure is used to build a tree structure representing
  55.  *        the expression given with the SELECT command.
  56.  */
  57. struct expr {
  58.     int        field;            /* Field to test, or boolean operator    */
  59.     int        op;                /* Operator to test against, if any        */
  60.     int        num;            /* First data field                        */
  61.     char    *text;            /* Second data field                    */
  62.     struct    expr *left;        /* Left subtree                            */
  63.     struct    expr *right;    /* Right subtree                        */
  64. };
  65.  
  66. typedef struct expr EXPR;
  67.  
  68. /*
  69.  *        This structure is used to hold the name of a file found in
  70.  *        a BBS-PC! file directory during CHECKFILES, which does not
  71.  *        exist in the BBS-PC! file catalogue.
  72.  */
  73. typedef struct {
  74.     char    name[32];        /* Disk filename                        */
  75.     short    date;            /* In BBS-PC! format, max 16 bits        */
  76.     short    dirnum;            /* The directory number it was in        */
  77.     long    size;            /* The size of the file, in bytes        */
  78. } DIRENTRY;
  79.  
  80. #define DIRENTRYSIZE    sizeof(DIRENTRY)
  81.  
  82. /*
  83.  *        This structure holds the names of files to be "ignored" during a
  84.  *        CHECKFILES. I.e. they are marked as valid, even if their filesize
  85.  *        on disk doesn't match that in the file catalogue. This structure
  86.  *        is built up with the IGNORE command.
  87.  */
  88. struct ignore {
  89.     struct ignore *next;
  90.     char name[CAT_LEN+1];
  91. };
  92.  
  93. typedef struct ignore IGNORE;
  94.  
  95. /*
  96.  *        This structure is used to store macro definitions. Note that
  97.  *        a single block is used to store both the macro and its definition.
  98.  *        The structure is dynamically sized at runtime, to fit whatever
  99.  *        size definition is given. The text[] array (nominally 1) gets
  100.  *        expanded to hold the definition.
  101.  */
  102. typedef struct {
  103.     char    name[MACROLEN];    /* Name of this macro                    */
  104.     int        size;            /* Size of macro text                     */
  105.     char    text[1];        /* Start of macro text                    */
  106. } MACRO;
  107.  
  108. #define MACROSIZE        (sizeof(MACRO) - 1)        /* The -1 is for text[1] */
  109.  
  110. /*
  111.  *        This structure holds a block of parameters for a macro that is
  112.  *        executing.
  113.  */
  114. typedef struct {
  115.     int        size;            /* Size of parameter block                */
  116.     char    params[1];        /* Start of parameter block                */
  117. } PARAM;
  118.  
  119. #define PARAMSIZE        (sizeof(PARAM) - 1)        /* The -1 is for params[1] */
  120.  
  121.  
  122. /*
  123.  *        This macro checks to make sure that the file database has been
  124.  *        read in. This is delayed until as late as possible, so that if
  125.  *        the script file contains errors, the errors will be spotted BEFORE
  126.  *        the database is read in. The primary goal here is to save the user
  127.  *        having to wait for 200K or so of database to be read in, just so
  128.  *        they can see they have an error in their script. Instead, the
  129.  *        database is only read in when a command cannot execute without
  130.  *        having access to the files. Such commands are SORT, SCAN, LIST,
  131.  *        CHECKFILES and FOREIGN.
  132.  */
  133. #define CHECKDATABASE() {if (!readfiles) readdatabase(databasename);}
  134.  
  135. /*
  136.  *        Global variables, accessible to all modules
  137.  */
  138.  
  139. #ifdef GLOBAL
  140. #undef GLOBAL
  141. #endif
  142. #ifdef MAIN
  143. #define GLOBAL
  144. #else
  145. #define GLOBAL extern
  146. #endif
  147.  
  148. GLOBAL char *script;            /* Array for storing the script                */
  149. GLOBAL long scriptsize;            /* The size of the current script            */
  150. GLOBAL long scriptpos;            /* Position in the current script            */
  151. GLOBAL long linenum;            /* Line number in script file                */
  152. GLOBAL char out[MAXOUT];        /* Array for storing the output lines        */
  153. GLOBAL char combuf[MAXCOM];        /* Buffer to hold a single command            */
  154. GLOBAL char formatstring[MAXCOM];/* Used to store the output format string    */
  155. GLOBAL char databasename[256];    /* The name of the BBS-PC! file database    */
  156. GLOBAL char configname[256];    /* The name of the BBS-PC! config file        */
  157. GLOBAL char scriptname[256];    /* The name of the current script file        */
  158. GLOBAL UDHEAD **ptrblock;        /* Array of pointers to file records        */
  159. GLOBAL long numrecs;            /* The number of file headers read in        */
  160. GLOBAL long compos;                /* Position on the current command line        */
  161. GLOBAL long comlen;                /* Length of current command line            */
  162. GLOBAL BPTR outfile;            /* Output file (Default is stdout)            */
  163. GLOBAL BPTR errorfile;            /* Standard error file (screen usually)        */
  164. GLOBAL BPTR dirlock;            /* Lock used when scanning directories        */
  165. GLOBAL struct FileInfoBlock *fib;/* Global fib struct on longword boundary    */
  166. GLOBAL int checkfiles;            /* TRUE if file directories were scanned    */
  167. GLOBAL int readfiles;            /* TRUE if database file has been read in    */
  168. GLOBAL int toscreen;            /* TRUE if output is to screen                */
  169. GLOBAL int totalbytes;            /* Total number of bytes output so far        */
  170. GLOBAL int totalfiles;            /* Total number of files output so far        */
  171. GLOBAL int curbytes;            /* Number of bytes output by last LIST/SCAN    */
  172. GLOBAL int curfiles;            /* Number of files output by last LIST/SCAN    */
  173. GLOBAL int sorted;                /* True if file array has been sorted        */
  174. GLOBAL EXPR tree[MAXEXPR];        /* Array to hold parsed SELECT expression    */
  175. GLOBAL int numdirentries;        /* Number of fake directory entries            */
  176. GLOBAL DIRENTRY *direntries[MAXDIRENT];/* Storage for ptrs to dir entries    */
  177. GLOBAL char dirnames[NUM_SECT][DIRNAMESIZE];/* Storage for directory names    */
  178. GLOBAL CFGINFO config[1];        /* BBS-PC! Configuration file structure        */
  179. GLOBAL MACRO *macros[MAXMACRO];    /* Array of ptrs to macro definitions        */
  180. GLOBAL int nummacros;            /* Number of macros currently defined        */
  181. GLOBAL PARAM *params[MAXNEST];    /* Array of pointers to macro parameters    */
  182. GLOBAL int nestlevel;            /* Current macro nest level                    */
  183. GLOBAL int tracemode;            /* Trace mode; TRUE if tracing enabled        */
  184. GLOBAL IGNORE *firstignore;        /* Pointer to first filename to ignore        */
  185.  
  186. /*
  187.  *        Global functions, accessible everywhere
  188.  */
  189.  
  190. char *format();        /* Format output string from file header + format spec    */
  191. char *echoformat();    /* Formats output string for ECHO command                */
  192. char *itoa();        /* Convert integer into ASCII format                    */
  193. char *getstring();    /* Get next string from command buffer                    */
  194. void *mymalloc();    /* Safe memory tracker that handles out of memory         */
  195. void *SafeAllocMem();/* Safe AllocMem that handles out of memory            */
  196. void execscript();    /* Executes all the commands in the current script        */
  197. void Cleanup();        /* Frees resources and exits program                    */
  198. void chkabort();    /* Checks for Control-C, and aborts if detected            */
  199. void putstring();    /* Outputs string to standard I/O                        */
  200. void flushout();    /* Flushes data buffer to output file                    */
  201. void parse();        /* Parse command line and build expression tree            */
  202. void readdatabase();/* Reads in the BBS-PC! UDHEAD.DAT file database        */
  203. void readconfigfile();/* Reads in the BBS-PC! CFGINFO.DAT file                */
  204. void print();        /* Prints a string to stderr                            */
  205. void com_select();    /* SELECT, specifies criteria for files to select        */
  206. void com_checkfiles();/* Scans file directories, updating catlague entries    */
  207. void com_sort();    /* Sorts file catalogue into a particular order            */
  208. void com_foreign();    /* Prints a list of all the unknown foreign files        */
  209. void com_norequest();/* Stop AmigaDos from putting up requesters            */
  210. int match();        /* Returns TRUE if record matches current selection        */
  211. int scandir();        /* Scans directory for files, returns TRUE if continue    */
  212. int sortcmp();        /* Internal routine used for sorting files                */
  213.  
  214. /*
  215.  *        print3()
  216.  *        --------
  217.  *        Prints 3 strings to standard error
  218.  */
  219. #define print2(s1,s2)     (print(s1), print(s2))
  220. #define print3(s1,s2,s3) (print(s1), print(s2), print(s3))
  221.  
  222. /*
  223.  *        The list of identifiers used by SORT and SELECT.
  224.  */
  225.  
  226. #define MAXINDEX 16
  227.  
  228. #define I_ANY            0
  229. #define I_ACCESS        1
  230. #define I_BINARY        2
  231. #define I_COMMENT        3
  232. #define I_DISKNAME        4
  233. #define I_SECTION        5
  234. #define I_ONLINE        6
  235. #define I_LOCAL            7
  236. #define I_NAME            8
  237. #define I_OWNER            9
  238. #define I_PATHNAME        10
  239. #define I_DIRECTORY        11
  240. #define I_DISKDIRNUM    12
  241. #define I_VALID            13
  242. #define I_DATE            14
  243. #define I_SIZE            15
  244. #define I_KSIZE            16
  245.  
  246. GLOBAL struct {
  247.     int tag;
  248.     char *name;
  249. } indexes[MAXINDEX]
  250. #ifdef MAIN
  251. = {
  252.  
  253. {    I_ACCESS,        "ACCESS"},        /* Number of times file was accessed    */
  254. {    I_BINARY,        "BINARY"},        /* True if Binary, False if text        */
  255. {    I_COMMENT,        "COMMENT"},        /* The file comment                        */
  256. {    I_DISKNAME,        "DISKNAME"},    /* The name of the file on disk            */
  257. {    I_SECTION,        "SECTION"},        /* # of the section the file is in        */
  258. {    I_ONLINE,        "ONLINE"},        /* True if file online                    */
  259. {    I_LOCAL,        "LOCAL"},        /* True if file uploaded locally        */
  260. {    I_NAME,            "NAME"},        /* The name of the file in the catalog    */
  261. {    I_OWNER,        "OWNER"},        /* The name of uploader of the file        */
  262. {    I_PATHNAME,        "PATHNAME"},    /* Pathname to file on disk                */
  263. {    I_DIRECTORY,    "DIRECTORY"},    /* # of directory file is in            */
  264. {    I_DISKDIRNUM,    "DISKDIRNUM"},    /* # of disk directory file is in        */
  265. {    I_VALID,        "VALID"},        /* True if file is Valid                */
  266. {    I_DATE,            "DATE"},        /* The date the file was uploaded        */
  267. {    I_SIZE,            "SIZE"},        /* The size of the file                    */
  268. {    I_KSIZE,        "KSIZE"}        /* The size of the file in K            */
  269. }
  270. #endif
  271. ;
  272.  
  273. GLOBAL char *months[]
  274. #ifdef MAIN
  275. = {
  276.     "xxx",
  277.     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  278.     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  279. }
  280. #endif
  281. ;
  282.  
  283. /*
  284.  *        Special characters that can occur in the script
  285.  */
  286. #define CHAR_TAB        '\t'
  287. #define CHAR_SPACE        ' '
  288. #define CHAR_HASH        '#'
  289. #define CHAR_NL            '\n'
  290. #define CHAR_ESC        '\\'
  291. #define CHAR_QUOTE        '\''
  292. #define CHAR_QUOTES        '\"'
  293. #define CHAR_SEMI        ';'
  294. #define CHAR_COMMA        ','
  295. #define CHAR_EQUALS        '='
  296. #define CHAR_DOLLAR        '$'
  297. #define CHAR_NULL        '\0'
  298.  
  299. #define CHAR_ASCEND        '+'
  300. #define CHAR_DESCEND    '-'
  301.  
  302. /*
  303.  *        The following symbols are used in the expression tree
  304.  */
  305.  
  306. /*
  307.  *        Boolean operations, which share storage with field selectors
  308.  */
  309.  
  310. #define E_AND        30    /* <left> AND <right>    */
  311. #define    E_OR        31    /* <left> OR <right>    */
  312. #define    E_NOT        32    /* NOT <left>            */
  313. #define E_ALL        33    /* Always true            */
  314.  
  315. /*
  316.  *        Comparison operators, used for comparing record elements
  317.  */
  318. #define    E_EQ        34    /* Record == Value        */
  319. #define E_NE        35    /* Record != Value        */
  320. #define E_LT        36    /* Record <  Value        */
  321. #define E_GT        37    /* Record >  Value        */
  322. #define E_LE        38    /* Record <= Value        */
  323. #define E_GE        39    /* Record >= Value        */
  324.  
  325. #define E_OPENPAR    40    /* Open parameter token        */
  326. #define E_CLOSEPAR    41    /* Close parameter token    */
  327.  
  328. #define E_NUMBER    42    /* Any numeric value        */
  329. #define E_STRING    43    /* Anything in quotes        */
  330. #define E_END        44    /* End of command line        */
  331.  
  332. #define E_TEXT        45    /* File is a text file        */
  333. #define E_REMOTE    46    /* File is a remote file    */
  334. #define E_INVALID    47    /* File is invalid            */
  335. #define E_OFFLINE    48    /* File is offline            */
  336.  
  337.  
  338. /*
  339.  *        Wildcard special fields for strings
  340.  */
  341. #define tokentowild(x) ((x)+50)
  342.  
  343. #define W_OWNER        tokentowild(I_OWNER)
  344. #define W_NAME        tokentowild(I_NAME)
  345. #define W_DISKNAME    tokentowild(I_DISKNAME)
  346. #define W_COMMENT    tokentowild(I_COMMENT)
  347.